package com.example.dinghao.zyfypt_312dh.model;


import com.example.dinghao.zyfypt_312dh.bean.VideoBean;
import com.example.dinghao.zyfypt_312dh.iface.VideoListener;
import com.example.dinghao.zyfypt_312dh.iface.Videoiface;
import com.example.dinghao.zyfypt_312dh.service.VideoService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;


public class VideoModel implements Videoiface {
    private Retrofit retrofit;
    private String BASEURL="http://amicool.neusoft.edu.cn/";
    public VideoModel() {
        retrofit=new Retrofit.Builder().baseUrl(BASEURL).addConverterFactory(GsonConverterFactory.create()).build();

    }


    @Override
    public void getResultList(String mod, int page, String SessionID, final VideoListener videoListener) {
        VideoService articleService=retrofit.create(VideoService.class);
        Call<List<VideoBean>> call=articleService.getResult(mod,page,SessionID);
        call.enqueue(new Callback<List<VideoBean>>() {
            @Override
            public void onResponse(Call<List<VideoBean>> call, Response<List<VideoBean>> response) {
                if (response.isSuccessful()&&  response!=null){
                    videoListener.onResponse(response.body());
                }
                else
                   videoListener.onFail("on response fail");
            }

            @Override
            public void onFailure(Call<List<VideoBean>> call, Throwable t) {
                videoListener.onFail(t.toString());


            }
        });

    }
}
